# 设置变量
$projectName = "WpfApp1"
$configuration = "Release"
$runtime = "win-x64"
$framework = "net8.0-windows"
$outputPath = "bin\Release\$framework\$runtime\publish"

# 清理旧的发布文件
Write-Host "正在清理旧的发布文件..."
if (Test-Path $outputPath) {
  Remove-Item -Path $outputPath -Recurse -Force
}

# 发布应用程序
Write-Host "正在发布应用程序..."
dotnet publish `
  --configuration $configuration `
  --runtime $runtime `
  --framework $framework `
  --self-contained true `
  -p:PublishSingleFile=true `
  -p:PublishReadyToRun=true `
  -p:DebugType=None `
  -p:DebugSymbols=false

# 创建发布包
Write-Host "正在创建发布包..."
$version = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("$outputPath\$projectName.exe").FileVersion
$zipFile = "bin\Release\$projectName-v$version.zip"

# 确保目录存在
$zipDir = Split-Path $zipFile -Parent
if (-not (Test-Path $zipDir)) {
  New-Item -ItemType Directory -Path $zipDir | Out-Null
}

# 创建 ZIP 文件
Compress-Archive -Path "$outputPath\*" -DestinationPath $zipFile -Force

Write-Host "发布完成！"
Write-Host "发布包位置: $zipFile" 